package lt.inkredibl.iit;

import java.awt.geom.Line2D.Double;

public class ConstraintBottom
	extends Constraint
{
	public ConstraintBottom(double y2)
	{
		super(y2);
	}

	public boolean inside(double val)
	{
		return val <= getC();
	}

	public boolean outside(double val)
	{
		return val > getC();
	}

	public void crop(Double ln)
	{
		if (outside(getVal1(ln)))
		{
			double mul = diffC(getVal1(ln)) / diff(ln);
			ln.y1 = getC();
			ln.x1 += (ln.x2 - ln.x1) * mul;
		}
		else
		{
			double mul = diffC(getVal2(ln)) / diff(ln);
			ln.y2 = getC();
			ln.x2 += (ln.x1 - ln.x2) * mul;
		}
	}

	@Override
	public double getVal1(Double ln)
	{
		return ln.y1;
	}

	@Override
	public double getVal2(Double ln)
	{
		return ln.y2;
	}
}
